<?php

namespace app\api\validate\fp;

use app\common\enum\fp\MediaType;
use app\common\enum\fp\PaymentType;
use app\common\enum\fp\PostType;
use app\common\enum\fp\VipUnlockEnum;
use think\Validate;

class PostValidate extends Validate
{
    protected $failException = true;

    protected $rule = [
        'content' => 'require|length:10,300',
        'media_url' => 'require|array',
        'user_id' => 'require',
        'post_id' => 'require',
        'creator_id' => 'require',
        'payment_type' => 'require|enum:' . PaymentType::class,
        'media_type' => 'require|enum:' . MediaType::class,
        'is_vip_unlock' => 'require|enum:' . VipUnlockEnum::class,
        'type' => 'enum:' . PostType::class,
        'title' => 'max:45',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'create' => ['content', 'visibility', 'media_type', 'media_url', 'is_vip_unlock', 'type', 'title'],
        'info' => ['user_id', 'post_id'],
        'unlock' => ['creator_id', 'post_id'],
        'userLastPost' => ['user_id'],
    ];

    public function __construct()
    {
        $this->field = [
            'content' => __('content'),
            'payment_type' => __('payment_type'),
            'media_type' => __('media_type'),
            'is_vip_unlock' => __('is_vip_unlock'),
            'type' => __('type'),
            'title' => __('video title'),
            'creator_id' => __('creator_id'),
        ];
        $this->message = array_merge($this->message, [
            'content.require' => __('Please input content'),
            'content.length' => __('content length'),
        ]);
        parent::__construct();
    }

}